package com.ymatou.userregister.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.userregister.service.ActivateCodeCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P2;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.UserCallService;
import com.ymttest.utils.TestDataManager;

public class Ts_ActivateCode {
	private static ActivateCodeCall activateCodeCall;
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("创建阿里用户接口");
	}

	@Before
	public void caseUp() throws Exception {
		activateCodeCall = new ActivateCodeCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(activateCodeCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_ActivateCode_001() {
		Logger.start(true,"生成邮箱激活码成功");
		try {
			Logger.comment("注册用户");
			String email = TestDataManager.getPhoneNum()+"@emailactive.com";
			UserCallService.registerUser(email, TestDataManager.getPhoneNum(),null);
			activateCodeCall.setData("id="+email);
			activateCodeCall.callService();

			Logger.verifyEquals(true, activateCodeCall.getReturnData().contains("http://www.ymatou.com/register?confirmation="), "验证返回信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_ActivateCode_002() {
		Logger.start(true,"输入未注册过的邮箱，成功");
		try {
			String email = TestDataManager.getRandomNum(4)+"NotExist@emailactive.com";
			UserCallService.registerUser(email, TestDataManager.getPhoneNum(),null);
			activateCodeCall.setData("id="+email);
			activateCodeCall.callService();

			Logger.verifyEquals(true, activateCodeCall.getReturnData().contains("http://www.ymatou.com/register?confirmation="), "验证返回信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_ActivateCode_003() {
		Logger.start(false,"输入空邮箱，失败");
		try {
			activateCodeCall.setData("id=''");
			activateCodeCall.callService();

			Logger.verifyEquals("\"未找到用户\"", activateCodeCall.getReturnData(), "验证返回信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_ActivateCode_004() {
		Logger.start(false,"不输入邮箱，失败");
		try {
			activateCodeCall.setData("id");
			activateCodeCall.callService();

			Logger.verifyEquals("\"id不能为空\"", activateCodeCall.getReturnData(), "验证返回信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
}
